require(['jquery', 'cookie', 'app', "lay"], function ($) {
    require(['vue'], function (Vue) {
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                where: "",
                that: {
                    parentId: "",
                    icon: "",
                    name: "",
                    series: "",
                    uri: "",
                    permissions: "",
                    status: "",
                    orders:""
                }
            }
            , created: function () {
                this.loadPage();
            }
            , methods: {
                loadPage: function () {
                    load();
                    var toolbar = [];
                    toolbar.push({
                        "clas": "layui-icon layui-icon-add-1",
                        "eve": "ADD",
                        "tit": "新增",
                        "fnc": function (data) {
                            dic.openAdd();
                        }
                    });
                    var tool = [];
                    tool.push({
                        "clas": "layui-btn-danger",
                        "eve": "EUDIT",
                        "tit": "修改",
                        "fnc": function (data) {
                            dic.that = data.data;
                            dic.that['status'] = false;
                            dic.openAdd();
                        }
                    });
                    treeTab($("#authoritiesTable"), "/menu/MenuController/menu/all/no", [
                        {type: 'checkbox'},
                        {type: 'numbers'},
                        {field: 'id', title: '菜单id'},
                        {field: 'name', title: '菜单名称', minWidth: 150},
                        {title: '菜单图标', templet: '<p><i class="{{d.icon}}"></i></p>', align: 'center', width: 100},
                        {field: 'uri', title: '菜单url'},
                        {field: 'permissions', title: '权限'},
                        {field: 'series', title: '层级', align: 'center', width: 80},
                        {
                            templet: '<p>{{# if(d.status==false){ }} 禁用 {{# } }}{{# if(d.status==true){ }} 启用 {{# } }}</p>',
                            align: 'center',
                            width: 100,
                            title: '状态'
                        },
                        {field: 'orders', title: '排序'},
                        {title: '操作', toolbar: '#authoritiesTbBar', align: 'center', width: 120}
                    ], function (data) {

                    }, this.where, toolbar, tool);
                },
                seachs: function () {
                    this.where = fromName($(".el-form"));
                    this.loadPage();
                },
                refer: function () {

                },
                openAdd: function () {
                    alrYN($("#admins"), function () {
                        var jon = dic.that;
                        jon['status'] = $('input[name="status"]').next().find("em").text();
                        jon['permissions'] = jon['permissions'] instanceof Array ? jon['permissions'] : jon['permissions'].split(",");
                        var ret = playPost("menu/MenuController/menu", "", JSON.stringify(jon));
                        alr(ret.msg);
                    }, function () {

                    }, function () {

                    }, "新增菜单", 1, ["600px", "350px"]);
                }
            }
        });
    })
});